#include<bits/stdc++.h>
#include<string>
#include<windows.h>
#include<fstream>
#include"printcolor.h"//setTextColor("") 字体颜色  setTextBackgroundColor("") 字体背景颜色 
using namespace std;
#define KEY_DOWN(VK_Code)((GetAsyncKeyState(VK_Code)&0x8000)?1:0)

HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord = {0, 0};

long long random(long long a, long long b){
	return (rand() % (b - a + 1)) + a; 
}

void cls(){
	CONSOLE_CURSOR_INFO cursor_info = {1, 0};
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
	SetConsoleCursorPosition(hOutput, coord);
}

string conv_string(long long n){
	string s = "";
	while(n){
		s += char(48 + n % 10);
		n /= 10;
	}
	string str = "";
	for(int i = s.size() - 1; i >= 0; i--){
		str += s[i];
	}
	return str;
}

void middle(string s){
    HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO bInfo;
    GetConsoleScreenBufferInfo(hOutput, &bInfo);
    int len = bInfo.dwSize.X / 2 - s.size() / 2;
    printf("\033[%dC", len);
    cout << s;
}

int identity_num = 9;

string identity[] = {"赌徒", "财主", "魔术师", "药剂师", "护士",
					 "医生", "警察", "小偷", "濒死者"};

string dj[] = {"普通", "普通", "普通", "次神", "次神",
			   "普通", "普通", "普通", "普通"};	    

string introduce[] = {
    "赌命：在不知道下一枪是空的还是实的的情况下朝自己开一枪，若是空弹，则下一发伤害翻倍。",
    "金钱：抽取道具时多抽一张。",
    "反转魔术：可以选择调转枪口/子弹（空->实，实->空）。",
    "药剂增幅：效果翻倍（道具，除放大镜外），可叠加",
    "治疗：回一点血",
    "强效治疗：将血量回满，每个人都回一点血。",
    "逮捕：获得手铐。",
    "偷盗：获得纸杯。",
    "死而复生：死后，丢弃2张道具，复活（2点血）。"
};

string name_introduce[] = {"赌命", "金钱", "反转魔术", "药剂增幅", "治疗", "强效治疗", "逮捕", "偷盗", "死而复生"};

int CD[] = {0, 0, 4, 5, 3, -1, 4, 3, 0}, late_round = 0; 

int lnitial_blood_volume[] = {6, 5, 6, 6, 6, 6, 7, 6, 4};

int Maximum_blood_volume[] = {8, 7, 8, 8, 8, 8, 8, 8, 5};

int Choose_identity(){
	int now_identity = 0;
	while(true){
		if(KEY_DOWN(VK_LEFT)){
			now_identity--;
			if(now_identity < 0){
				now_identity = identity_num - 1;
			}
			Sleep(145);
			system("cls");
		}
		if(KEY_DOWN(VK_RIGHT)){
			now_identity++;
			if(now_identity >= identity_num){
				now_identity = 0;
			}
			Sleep(145);
			system("cls");
		}
		setTextColor("lightblue");
		middle("选择身份\n"); 
		setTextColor("");
		setTextColor("red");
		middle(identity[now_identity]);
		cout << "\n";
		if(dj[now_identity] == "普通"){
			setTextColor("littlewhite");
		}else if(dj[now_identity] == "次神"){
			setTextColor("pink");
		}else{
			setTextColor("lightpink");
		}
		middle(dj[now_identity] + "\n");
		setTextColor("");
		cout << "\n\n";
		middle(introduce[now_identity]);
		cout << "\n\n";
		if(CD[now_identity] > 0){
			cout << "冷却：" << CD[now_identity] << "回合"; 
		}else if(CD[now_identity] == 0){
			cout << "无冷却"; 
		}else{
			cout << "全局可用" << -CD[now_identity] << "次"; 
		} 
		cout << "\n\n";
		cout << "初始血量：" <<  lnitial_blood_volume[now_identity] << "点\n"; 
		cout << "最高血量：" <<  Maximum_blood_volume[now_identity] << "点\n"; 
		cls();
		if(KEY_DOWN(VK_RETURN)){
			if(MessageBox (NULL, "确定选择此身份吗？", "提示", MB_OKCANCEL|MB_ICONQUESTION) == IDOK){
				break;
			}
		} 
	}
	system("cls");
	return now_identity;
}

int mode_num = 1;

string modelist[] = {"恶魔轮盘"};

string mode_introduce[] = {
	"1名玩家vs电脑恶魔，玩家将和恶魔进行普通版恶魔轮盘"				
};

int choose_mode(){
	int now_mode = 0;
	while(true){
		if(KEY_DOWN(VK_LEFT)){
			now_mode--;
			if(now_mode < 0){
				now_mode = mode_num - 1;
			}
			Sleep(145);
			system("cls");
		}
		if(KEY_DOWN(VK_RIGHT)){
			now_mode++;
			if(now_mode >= mode_num){
				now_mode = 0;
			}
			Sleep(145);
			system("cls");
		}
		setTextColor("lightblue");
		middle("选择模式\n"); 
		setTextColor("");
		setTextColor("red");
		middle(modelist[now_mode]);
		setTextColor("");
		cout << "\n\n\n\n";
		middle(mode_introduce[now_mode]);
		cout << "\n\n";
		cls();
		if(KEY_DOWN(VK_RETURN)){
			if(MessageBox (NULL, "确定选择此模式吗？", "提示", MB_OKCANCEL|MB_ICONQUESTION) == IDOK){
				break;
			}
		} 
	}
	system("cls");
	return now_mode;
}

void Buckshot_Roulette_Start(){
	system("mode con cols=25 lines=3");
	system("cls");
	setTextColor("red");
	middle("恶魔轮盘\n\n");
	setTextColor("");
	Sleep(1000);
	middle("开始");
	Sleep(500);
}

//小刀 饮料 放大镜 手铐 纸杯 激光笔 过期药品 
string name_prop[] = {"小刀", "饮料", "放大镜", "手铐", "纸杯", "激光笔", "过期药品"};
int em_prop[] = {0, 0, 0, 0, 0, 0, 0};
int wj_prop[] = {0, 0, 0, 0, 0, 0, 0};
int eorr[] = {0, 0, 0, 0, 0, 0}, sysd = 0, sykd = 0; 
int roundnum = 0, emxd = 0, wjxd = 0, wjdjs = 0, emdjs = 0, nowf = 0, idid;
int wjh;
int wj_max;
int emh;
int em_max;

void zd(){
	sysd = random(1, 6);
	sykd = 6 - sysd;
	int s = sysd, k = sykd;
	for(int i = 0; i < 6; i++){
		bool er = random(0, 1);
		while(true){
			er = random(0, 1);
			if(er){
				if(s > 0){
					s--;
					eorr[i] = 1;
					break;
				}
			}else{
				if(k > 0){
					k--;
					eorr[i] = 0;
					break;
				}
			}
		}
	}
	nowf = 5;
}

void xsh(){
	emh = max(emh, 0);
	wjh = max(wjh, 0);
	cls();
	setTextColor("lightred");
	middle("恶魔轮盘\n\n");
	setTextColor("lightblue");
	middle("第" + conv_string(roundnum) + "回合\n");
	setTextColor("");
	middle("------------------------------------------------\n");
	setTextColor("red");
	middle("恶魔\n");
	setTextColor("");
	for(int i = 0; i < 7; i++){
		cout << name_prop[i] << ":" << em_prop[i];
		if(i % 3 == 0 && i > 0){
			cout << "\n";
		}else{
			cout << "      ";
		}
	}
	cout << "\n\n";
	setTextColor("red");
	cout << "血量:"; 
	setTextColor("");
	cout << emh << "点\n";
	middle("------------------------------------------------\n");
	setTextColor("skyblue");
	middle(identity[idid] + "\n");
	if(dj[idid] == "普通"){
		setTextColor("littlewhite");
	}else if(dj[idid] == "次神"){
		setTextColor("pink");
	}else{
		setTextColor("lightpink");
	}
	middle(dj[idid] + "\n");
	setTextColor("");
	for(int i = 0; i < 7; i++){
		cout << name_prop[i] << ":" << wj_prop[i];
		if(i % 3 == 0 && i > 0){
			cout << "\n";
		}else{
			cout << "     ";
		}
	}
	setTextColor("lightyellow");
	cout << "技能：";
	setTextColor("");
	if(CD[idid] > 0){
		if(late_round == 0 || roundnum - late_round - 1 >= CD[idid]){
			setTextColor("green");
		}else{
			setTextColor("littlewhite");
		}
	}else{
		if(CD[idid] == 0){
			setTextColor("yellow");
		}else{
			setTextColor("pink");
		}
	}
	cout << name_introduce[idid];
	setTextColor("");
	cout << "\n\n";
	setTextColor("red");
	cout << "血量:"; 
	setTextColor("");
	cout << wjh << "点\n";
	setTextColor("red");
	cout << "最高血量:"; 
	setTextColor("");
	cout << wj_max << "点\n";
	middle("------------------------------------------------\n");
}

string emyl[105];

//小刀 饮料 放大镜 手铐 纸杯 激光笔 过期药品 
int em_round(){
	setTextColor("lightred");
	middle("恶魔行动\n");
	setTextColor("");
	int propnum = 0, sjgl = 0, fb = 1;
	while(propnum < 2 || emdjs > 0){
		if(emh <= em_max * 0.7){
			if(em_prop[1] > 0){
				emh++;
				emdjs--;
				em_prop[1]--;
				xsh();
				setTextColor("lightred");
				middle("恶魔行动\n");
				setTextColor("");
				for(int i = 0; i < propnum; i++){
					middle(emyl[i] + "\n");
				}
				emyl[propnum] = "恶魔使用了 饮料 道具";
				middle(emyl[propnum] + "\n");
				Sleep(random(500, 1100));
				propnum++;
				if(propnum >= 2 || emdjs <= 0){
					break;
				} 
			}else{
				if(em_max * 0.4 <= emh && em_prop[6] > 0){
					em_prop[6]--;
					emdjs--;
					if(random(1, 100) <= 40){
						emh += 1;
					}else{
						emh--;
					}
					xsh();
					setTextColor("lightred");
					middle("恶魔行动\n");
					setTextColor("");
					for(int i = 0; i < propnum; i++){
						middle(emyl[i] + "\n");
					}
					emyl[propnum] = "恶魔使用了 过期药品 道具";
					middle(emyl[propnum] + "\n");
					Sleep(random(500, 1100));
					propnum++;
					if(propnum >= 2 || emdjs <= 0){
						break;
					} 
				}
			}
		}
		if(em_prop[2] > 0){
			em_prop[2]--;
			emdjs--;
			xsh();
			setTextColor("lightred");
			middle("恶魔行动\n");
			setTextColor("");
			for(int i = 0; i < propnum; i++){
				middle(emyl[i] + "\n");
			}
			emyl[propnum] = "恶魔使用了 放大镜 道具";
			middle(emyl[propnum] + "\n");
			Sleep(random(500, 1100));
			propnum++;
			if(eorr[nowf] == 0){
				sjgl = 2;
			}else{
				sjgl = 1;
			}
			if(em_prop[0] > 0 && sjgl == 1){
				em_prop[0]--;
				emdjs--;
				xsh();
				setTextColor("lightred");
				middle("恶魔行动\n");
				setTextColor("");
				for(int i = 0; i < propnum; i++){
					middle(emyl[i] + "\n");
				}
				emyl[propnum] = "恶魔使用了 小刀 道具";
				middle(emyl[propnum] + "\n");
				Sleep(random(500, 1100));
				propnum++;
				fb = 2;
			}
			if(propnum >= 2 || emdjs <= 0){
				break;
			}
		}
		if(em_prop[3] > 0){
			em_prop[3]--;
			emdjs--;
			wjxd++;
			xsh();
			setTextColor("lightred");
			middle("恶魔行动\n");
			setTextColor("");
			for(int i = 0; i < propnum; i++){
				middle(emyl[i] + "\n");
			}
			emyl[propnum] = "恶魔使用了 手铐 道具"; 
			middle(emyl[propnum] + "\n");
			Sleep(random(500, 1100));
			propnum++;
			if(propnum >= 2 || emdjs <= 0){
				break;
			}
		}
		if(em_prop[4] > 0 && wjdjs > 0){
			em_prop[4]--;
			emdjs--;
			emyl[propnum] = "恶魔使用了 纸杯 道具";
			while(true){
				int myx = random(0, 6);
				if(wj_prop[myx] > 0){
					wj_prop[myx]--;
					wjdjs--;
					em_prop[myx]++;
					emdjs++;
					emyl[propnum] = "恶魔使用了 纸杯 道具，偷走了 " + name_prop[myx] + " 道具";
					break;
				}
			}
			xsh();
			setTextColor("lightred");
			middle("恶魔行动\n");
			setTextColor("");
			for(int i = 0; i < propnum; i++){
				middle(emyl[i] + "\n");
			}
			middle(emyl[propnum] + "\n");
			Sleep(random(500, 1100));
			propnum++;
			if(propnum >= 2 || emdjs <= 0){
				break;
			}
		}
		if(em_prop[5] > 0 && wjdjs > 0){
			em_prop[5]--;
			emdjs--;
			emyl[propnum] = "恶魔使用了 激光笔 道具";
			if(wj_prop[3] > 0){
				wj_prop[3]--;
				emyl[propnum] = "恶魔使用了 激光笔 道具，消除了 手铐 道具";
			}else if(wj_prop[0] > 0){
				wj_prop[0]--;
				emyl[propnum] = "恶魔使用了 激光笔 道具，消除了 小刀 道具";
			}else if(wj_prop[2] > 0){
				wj_prop[2]--;
				emyl[propnum] = "恶魔使用了 激光笔 道具，消除了 放大镜 道具";
			}else if(wj_prop[4] > 0){
				wj_prop[4]--;
				emyl[propnum] = "恶魔使用了 激光笔 道具，消除了 纸杯 道具";
			}else if(wj_prop[1] > 0){
				wj_prop[1]--;
				emyl[propnum] = "恶魔使用了 激光笔 道具，消除了 饮料 道具";
			}else if(wj_prop[5] > 0){
				wj_prop[5]--;
				emyl[propnum] = "恶魔使用了 激光笔 道具，消除了 激光笔 道具";
			}else if(wj_prop[6] > 0){
				wj_prop[6]--;
				emyl[propnum] = "恶魔使用了 激光笔 道具，消除了 过期药品 道具";
			}
			xsh();
			setTextColor("lightred");
			middle("恶魔行动\n");
			setTextColor("");
			for(int i = 0; i < propnum; i++){
				middle(emyl[i] + "\n");
			}
			middle(emyl[propnum] + "\n");
			Sleep(random(500, 1100));
			propnum++;
			if(propnum >= 2 || emdjs <= 0){
				break;
			}
		}
		if(em_prop[1] > 0){
			emh++;
			emdjs--;
			em_prop[1]--;
			xsh();
			setTextColor("lightred");
			middle("恶魔行动\n");
			setTextColor("");
			for(int i = 0; i < propnum; i++){
				middle(emyl[i] + "\n");
			}
			emyl[propnum] = "恶魔使用了 饮料 道具";
			middle(emyl[propnum] + "\n");
			Sleep(random(500, 1100));
			propnum++;
			if(propnum >= 2 || emdjs <= 0){
				break;
			} 
		}
		if(em_prop[0] > 0 && sjgl != 2){
			em_prop[0]--;
			emdjs--;
			xsh();
			setTextColor("lightred");
			middle("恶魔行动\n");
			setTextColor("");
			for(int i = 0; i < propnum; i++){
				middle(emyl[i] + "\n");
			}
			emyl[propnum] = "恶魔使用了 小刀 道具";
			middle(emyl[propnum] + "\n");
			Sleep(random(500, 1100));
			propnum++;
			fb = 2;
			if(propnum >= 2 || emdjs <= 0){
				break;
			}
		}
		if(em_prop[6] > 0){
			em_prop[6]--;
			emdjs--;
			if(random(1, 100) <= 40){
				emh += 2;
			}else{
				emh--;
			}
			xsh();
			setTextColor("lightred");
			middle("恶魔行动\n");
			setTextColor("");
			for(int i = 0; i < propnum; i++){
				middle(emyl[i] + "\n");
			}
			emyl[propnum] = "恶魔使用了 过期药品 道具";
			middle(emyl[propnum] + "\n");
			Sleep(random(500, 1100));
			propnum++;
			if(propnum >= 2 || emdjs <= 0){
				break;
			} 
		}
	}
	
	// 修改核心逻辑：根据eorr[nowf]决定开枪目标
	int mszy = -1;
	if(idid == 2 && (late_round == 0 || roundnum - late_round - 1 >= CD[idid])){
		string s;
		do{
			setTextColor("lightyellow");
			cout << "技能：";
			setTextColor("");
			cout << "恶魔即将开枪，是否使用技能";
			setTextColor("green");
			cout << " 反转魔术 ";
			setTextColor("");
			cout << "，反转 枪口/子弹（使用：枪口/子弹 不使用：否）：";
			cin >> s;
		}while(s != "枪口" && s != "子弹" && s != "否");
		system("cls");
		xsh();
		setTextColor("lightred");
		middle("恶魔行动\n");
		setTextColor("");
		for(int i = 0; i < propnum; i++){
			middle(emyl[i] + "\n");
		}
		if(s != "否"){
			late_round = roundnum;
			if(s == "枪口"){
				mszy = 1;
			}else{
				mszy = 2;
			}
		}
	}
	
	// 核心逻辑：eorr[nowf]为1时恶魔朝玩家开枪，为0时朝自己开枪
	if(eorr[nowf] == 1) {
		// 实弹，朝玩家开枪
		if(mszy == 1) {
			// 枪口反转，朝自己开枪
			emh -= fb;
			nowf--;
			if(nowf < 0) zd();
			xsh();
			emyl[propnum] = "恶魔朝 自己 开枪，是实弹，ta掉" + conv_string(fb) + "滴血(枪口被反转)";
		} else if(mszy == 2) {
			// 子弹反转，空弹
			wjh += fb;
			nowf--;
			if(nowf < 0) zd();
			xsh();
			emyl[propnum] = "恶魔朝 你 开枪，是空弹(子弹被反转)";
		} else {
			// 正常朝玩家开枪
			wjh -= fb;
			nowf--;
			if(nowf < 0) zd();
			xsh();
			emyl[propnum] = "恶魔朝 你 开枪，是实弹，你掉" + conv_string(fb) + "滴血";
		}
	} else {
		// 空弹，朝自己开枪
		if(mszy == 1) {
			// 枪口反转，朝玩家开枪
			wjh -= fb;
			nowf--;
			if(nowf < 0) zd();
			xsh();
			emyl[propnum] = "恶魔朝 你 开枪，是实弹，你掉" + conv_string(fb) + "滴血(枪口被反转)";
		} else if(mszy == 2) {
			// 子弹反转，实弹
			emh -= fb;
			nowf--;
			if(nowf < 0) zd();
			xsh();
			emyl[propnum] = "恶魔朝 自己 开枪，是实弹，ta掉" + conv_string(fb) + "滴血(子弹被反转)";
		} else {
			// 正常朝自己开枪
			nowf--;
			if(nowf < 0) zd();
			xsh();
			emyl[propnum] = "恶魔朝 自己 开枪，是空弹";
		}
	}
	
	middle(emyl[propnum] + "\n");
	Sleep(random(500, 1100));
	fb = 1;
	
	// 处理额外开枪逻辑
	while(wjxd > 0){
		wjxd--;
		propnum++;
		if(random(1, 100) <= 75){
			int mszy = -1;
			if(idid == 2 && (late_round == 0 || roundnum - late_round - 1 >= CD[idid])){
				string s;
				do{
					setTextColor("lightyellow");
					cout << "技能：";
					setTextColor("");
					cout << "恶魔朝 你 开枪，是否使用技能";
					setTextColor("green");
					cout << " 反转魔术 ";
					setTextColor("");
					cout << "，反转 枪口/子弹（使用：枪口/子弹 不使用：否）：";
					cin >> s;
				}while(s != "枪口" && s != "子弹" && s != "否");
				system("cls");
				xsh();
				setTextColor("lightred");
				middle("恶魔行动\n");
				setTextColor("");
				for(int i = 0; i < propnum; i++){
					middle(emyl[i] + "\n");
				}
				if(s != "否"){
					late_round = roundnum;
					if(s == "枪口"){
						mszy = 1;
					}else{
						mszy = 2;
					}
				}
			}
			if(eorr[nowf] == 1){
				wjh -= fb;
				nowf--;
				if(nowf < 0){
					zd();
				}
				xsh();
				setTextColor("lightred");
				middle("恶魔行动\n");
				setTextColor("");
				for(int i = 0; i < propnum; i++){
					middle(emyl[i] + "\n");
				}
				emyl[propnum] = "恶魔朝 你 开枪，是实弹，你掉" + conv_string(fb) + "滴血";
				if(mszy > 0){
					if(mszy == 1){
						wjh += fb;
						emh -= fb;
						xsh();
						setTextColor("lightred");
						middle("恶魔行动\n");
						setTextColor("");
						for(int i = 0; i < propnum; i++){
							middle(emyl[i] + "\n");
						}
						emyl[propnum] = "恶魔朝 自己 开枪，是实弹，ta掉" + conv_string(fb) + "滴血(枪口被反转)";
					}else{
						wjh += fb;
						xsh();
						setTextColor("lightred");
						middle("恶魔行动\n");
						setTextColor("");
						for(int i = 0; i < propnum; i++){
							middle(emyl[i] + "\n");
						}
						emyl[propnum] = "恶魔朝 你 开枪，是空弹(子弹被反转)";
					}
				}
				middle(emyl[propnum] + "\n");
				Sleep(random(500, 1100));
			}else{
				nowf--;
				if(nowf < 0){
					zd();
				}
				xsh();
				setTextColor("lightred");
				middle("恶魔行动\n");
				setTextColor("");
				for(int i = 0; i < propnum; i++){
					middle(emyl[i] + "\n");
				}
				emyl[propnum] = "恶魔朝 你 开枪，是空弹";
				if(mszy > 0){
					if(mszy == 1){
						xsh();
						setTextColor("lightred");
						middle("恶魔行动\n");
						setTextColor("");
						for(int i = 0; i < propnum; i++){
							middle(emyl[i] + "\n");
						}
						emyl[propnum] = "恶魔朝 自己 开枪，是空弹(枪口被反转)";
						wjxd++;
					}else{
						wjh -= fb;
						xsh();
						setTextColor("lightred");
						middle("恶魔行动\n");
						setTextColor("");
						for(int i = 0; i < propnum; i++){
							middle(emyl[i] + "\n");
						}
						emyl[propnum] = "恶魔朝 你 开枪，是实弹，你掉" + conv_string(fb) + "滴血(子弹被反转)";
					}
				}
				middle(emyl[propnum] + "\n");
				Sleep(random(500, 1100));
			}
		}else{
			int mszy = -1;
			if(idid == 2 && (late_round == 0 || roundnum - late_round - 1 >= CD[idid])){
				string s;
				do{
					setTextColor("lightyellow");
					cout << "技能：";
					setTextColor("");
					cout << "恶魔朝 自己 开枪，是否使用技能";
					setTextColor("green");
					cout << " 反转魔术 ";
					setTextColor("");
					cout << "，反转 枪口/子弹（使用：枪口/子弹 不使用：否）：";
					cin >> s;
				}while(s != "枪口" && s != "子弹" && s != "否");
				system("cls");
				xsh();
				setTextColor("lightred");
				middle("恶魔行动\n");
				setTextColor("");
				for(int i = 0; i < propnum; i++){
					middle(emyl[i] + "\n");
				}
				if(s != "否"){
					late_round = roundnum;
					if(s == "枪口"){
						mszy = 1;
					}else{
						mszy = 2;
					}
				}
			}
			if(eorr[nowf] == 1){
				emh -= fb;
				nowf--;
				if(nowf < 0){
					zd();
				}
				xsh();
				setTextColor("lightred");
				middle("恶魔行动\n");
				setTextColor("");
				for(int i = 0; i < propnum; i++){
					middle(emyl[i] + "\n");
				}
				emyl[propnum] = "恶魔朝 自己 开枪，是实弹，ta掉" + conv_string(fb) + "滴血";
				if(mszy > 0){
					if(mszy == 1){
						emh += fb;
						wjh -= fb;
						xsh();
						setTextColor("lightred");
						middle("恶魔行动\n");
						setTextColor("");
						for(int i = 0; i < propnum; i++){
							middle(emyl[i] + "\n");
						}
						emyl[propnum] = "恶魔朝 你 开枪，是实弹，你掉" + conv_string(fb) + "滴血(枪口被反转)";
					}else{
						emh += fb;
						xsh();
						setTextColor("lightred");
						middle("恶魔行动\n");
						setTextColor("");
						for(int i = 0; i < propnum; i++){
							middle(emyl[i] + "\n");
						}
						emyl[propnum] = "恶魔朝 自己 开枪，是空弹(子弹被反转)";
						wjxd++;
					}
				}
				middle(emyl[propnum] + "\n");
				Sleep(random(500, 1100));
			}else{
				nowf--;
				if(nowf < 0){
					zd();
				}
				xsh();
				setTextColor("lightred");
				middle("恶魔行动\n");
				setTextColor("");
				for(int i = 0; i < propnum; i++){
					middle(emyl[i] + "\n");
				}
				emyl[propnum] = "恶魔朝 自己 开枪，是空弹";
				if(mszy > 0){
					if(mszy == 1){
						xsh();
						setTextColor("lightred");
						middle("恶魔行动\n");
						setTextColor("");
						for(int i = 0; i < propnum; i++){
							middle(emyl[i] + "\n");
						}
						emyl[propnum] = "恶魔朝 你 开枪，是空弹(枪口被反转)";
						wjxd--;
					}else{
						emh -= fb;
						xsh();
						setTextColor("lightred");
						middle("恶魔行动\n");
						setTextColor("");
						for(int i = 0; i < propnum; i++){
							middle(emyl[i] + "\n");
						}
						emyl[propnum] = "恶魔朝 自己 开枪，是实弹，ta掉" + conv_string(fb) + "滴血(子弹被反转)";
						wjxd--;
					}
				}
				middle(emyl[propnum] + "\n");
				Sleep(random(500, 1100));
				wjxd++;
			}
		}
	}
	return propnum;
}

string wjyl[105];

//小刀 饮料 放大镜 手铐 纸杯 激光笔 过期药品 
void wj_round(int cd){
	getchar();
	Sleep(125);
	getchar();
	getchar();
	int propnum = 0, fb = 1, lk = 1;
	bool fdjsy = 0;
	while(propnum < 2){
		system("cls");
		xsh();
		setTextColor("lightred");
		middle("恶魔行动\n");
		setTextColor("");
		for(int i = 0; i <= cd; i++){
			middle(emyl[i] + "\n");
		}
		cout << "\n";
		setTextColor("blue");
		middle("玩家行动\n");
		setTextColor("");
		for(int i = 0; i < propnum; i++){
			middle(wjyl[i]);
		}
		if((late_round == 0 || roundnum - late_round - 1 >= CD[idid]) && idid == 4){
			cout << "是否使用 ";
			setTextColor("green");
			cout << "治疗 ";
			setTextColor("");
			cout << "回复1点血(是/否~不为'是'判为'否'):";
			string str;
			cin >> str;
			if(str == "是"){
				middle("技能 使用成功，回复一点血~\n");
				wjh++;
				if(wjh >= wj_max){
					middle("已达血量上限~\n");
					wjh = wj_max; 
				}
				Sleep(500);
				late_round = roundnum; 
				continue;
			}
		}
		cout << "请使用道具(输入道具名称，退出按0)：";
		string s;
		getline(cin, s);
		if(s == "小刀"){
			if(wj_prop[0] > 0){
				wjdjs--;
				wj_prop[0]--;
				wjyl[propnum] = "小刀 使用成功，下一枪伤害翻倍~\n";
				fb *= 2;
				middle(wjyl[propnum]);
				if((late_round == 0 || roundnum - late_round - 1 >= CD[idid]) && idid == 3){
					cout << "是否使用 ";
					setTextColor("green");
					cout << "药剂增幅 ";
					setTextColor("");
					cout << "令此道具效果翻倍(是/否~不为'是'判为'否'):";
					string str;
					cin >> str;
					if(str == "是"){
						middle("增幅成功~\n");
						Sleep(500);
						fb *= 2;
						late_round = roundnum;
					}
				}
				propnum++;
				continue;
			}else{
				middle("暂无此道具");
				Sleep(700);
				continue;
			}
		}else if(s == "饮料"){
			if(wj_prop[1] > 0){
				wjdjs--;
				wj_prop[1]--;
				wjyl[propnum] = "饮料 使用成功，回复一点血~\n";
				wjh++;
				if(wjh >= wj_max){
					wjyl[propnum] = "饮料 使用成功，血量已达上限~\n";
					wjh = wj_max; 
				}
				middle(wjyl[propnum]);
				if((late_round == 0 || roundnum - late_round - 1 >= CD[idid]) && idid == 3){
					cout << "是否使用 ";
					setTextColor("green");
					cout << "药剂增幅 ";
					setTextColor("");
					cout << "令此道具效果翻倍(是/否~不为'是'判为'否'):";
					string str;
					cin >> str;
					if(str == "是"){
						middle("增幅成功，再回一点血~\n");
						Sleep(500);
						wjh++;
						wjyl[propnum] = "饮料 使用成功，回复两点血~\n";
						if(wjh >= wj_max){
							wjyl[propnum] = "饮料 使用成功，血量已达上限~\n";
							wjh = wj_max; 
						}
						late_round = roundnum;
					}
				}
				propnum++;
				continue;
			}else{
				middle("暂无此道具");
				Sleep(700);
				continue;
			}
		}else if(s == "放大镜"){
			if(wj_prop[2] > 0){
				wjdjs--;
				wj_prop[2]--;
				wjyl[propnum] = "放大镜 使用成功~\n";
				fdjsy = 1;
				Sleep(150);
				if(eorr[nowf] == 0)
					middle("下一发子弹是 空 ~");
				else
					middle("下一发子弹是 实 ~");
				Sleep(1000);
				propnum++;
				continue;
			}else{
				middle("暂无此道具");
				Sleep(700);
				continue;
			}
		}else if(s == "手铐"){
			if(wj_prop[3] > 0){
				wjdjs--;
				wj_prop[3]--;
				wjyl[propnum] = "手铐 使用成功，可多开一枪~\n";
				middle(wjyl[propnum]);
				if((late_round == 0 || roundnum - late_round - 1 >= CD[idid]) && idid == 3){
					cout << "是否使用 ";
					setTextColor("green");
					cout << "药剂增幅 ";
					setTextColor("");
					cout << "令此道具效果翻倍(是/否~不为'是'判为'否'):";
					string str;
					cin >> str;
					if(str == "是"){
						middle("增幅成功，再多开一枪~\n");
						Sleep(500);
						lk++;
						late_round = roundnum;
					}
				}
				lk++;
				propnum++;
				continue;
			}else{
				middle("暂无此道具");
				Sleep(700);
				continue;
			}
		}else if(s == "纸杯"){
			if(wj_prop[4] > 0){
				wjdjs--;
				wj_prop[4]--;
				wjyl[propnum] = "纸杯 使用成功~\n";
				middle(wjyl[propnum]);
				if((late_round == 0 || roundnum - late_round - 1 >= CD[idid]) && idid == 3){
					cout << "是否使用 ";
					setTextColor("green");
					cout << "药剂增幅 ";
					setTextColor("");
					cout << "令此道具效果翻倍(是/否~不为'是'判为'否'):";
					string str;
					cin >> str;
					if(str == "是"){
						middle("增幅成功，再多偷一个道具~\n");
						Sleep(500);
						do{
							cout << "你要偷走什么(道具)：";
							string s;
							getline(cin, s);
							if(s == "小刀" && em_prop[0] > 0){
								emdjs--; 
								em_prop[0]--;
								wjdjs++; 
								wj_prop[0]++;
								wjyl[propnum] = "纸杯 使用成功，成功偷走恶魔的 小刀 道具~\n";
								break;
							}else if(s == "饮料" && em_prop[1] > 0){
								emdjs--; 
								em_prop[1]--;
								wjdjs++; 
								wj_prop[1]++;
								wjyl[propnum] = "纸杯 使用成功，成功偷走恶魔的 饮料 道具~\n";
								break;
							}else if(s == "放大镜" && em_prop[2] > 0){
								emdjs--; 
								em_prop[2]--;
								wjdjs++; 
								wj_prop[2]++;
								wjyl[propnum] = "纸杯 使用成功，成功偷走恶魔的 放大镜 道具~\n";
								break;
							}else if(s == "手铐" && em_prop[3] > 0){
								emdjs--; 
								em_prop[3]--;
								wjdjs++; 
								wj_prop[3]++;
								wjyl[propnum] = "纸杯 使用成功，成功偷走恶魔的 手铐 道具~\n";
								break;
							}else if(s == "纸杯" && em_prop[4] > 0){
								emdjs--; 
								em_prop[4]--;
								wjdjs++; 
								wj_prop[4]++;
								wjyl[propnum] = "纸杯 使用成功，成功偷走恶魔的 纸杯 道具~\n";
								break;
							}else if(s == "激光笔" && em_prop[5] > 0){
								emdjs--; 
								em_prop[5]--;
								wjdjs++; 
								wj_prop[5]++;
								wjyl[propnum] = "纸杯 使用成功，成功偷走恶魔的 激光笔 道具~\n";
								break;
							}else if(s == "过期药品" && em_prop[6] > 0){
								emdjs--; 
								em_prop[6]--;
								wjdjs++; 
								wj_prop[6]++;
								wjyl[propnum] = "纸杯 使用成功，成功偷走恶魔的 过期药品 道具~\n";
								break;
							}
						}while(true);
						late_round = roundnum;
					}
				}
				do{
					cout << "你要偷走什么(道具)：";
					string s;
					getline(cin, s);
					if(s == "小刀" && em_prop[0] > 0){
						emdjs--; 
						em_prop[0]--;
						wjdjs++; 
						wj_prop[0]++;
						wjyl[propnum] = "纸杯 使用成功，成功偷走恶魔的 小刀 道具~\n";
						break;
					}else if(s == "饮料" && em_prop[1] > 0){
						emdjs--; 
						em_prop[1]--;
						wjdjs++; 
						wj_prop[1]++;
						wjyl[propnum] = "纸杯 使用成功，成功偷走恶魔的 饮料 道具~\n";
						break;
					}else if(s == "放大镜" && em_prop[2] > 0){
						emdjs--; 
						em_prop[2]--;
						wjdjs++; 
						wj_prop[2]++;
						wjyl[propnum] = "纸杯 使用成功，成功偷走恶魔的 放大镜 道具~\n";
						break;
					}else if(s == "手铐" && em_prop[3] > 0){
						emdjs--; 
						em_prop[3]--;
						wjdjs++; 
						wj_prop[3]++;
						wjyl[propnum] = "纸杯 使用成功，成功偷走恶魔的 手铐 道具~\n";
						break;
					}else if(s == "纸杯" && em_prop[4] > 0){
						emdjs--; 
						em_prop[4]--;
						wjdjs++; 
						wj_prop[4]++;
						wjyl[propnum] = "纸杯 使用成功，成功偷走恶魔的 纸杯 道具~\n";
						break;
					}else if(s == "激光笔" && em_prop[5] > 0){
						emdjs--; 
						em_prop[5]--;
						wjdjs++; 
						wj_prop[5]++;
						wjyl[propnum] = "纸杯 使用成功，成功偷走恶魔的 激光笔 道具~\n";
						break;
					}else if(s == "过期药品" && em_prop[6] > 0){
						emdjs--; 
						em_prop[6]--;
						wjdjs++; 
						wj_prop[6]++;
						wjyl[propnum] = "纸杯 使用成功，成功偷走恶魔的 过期药品 道具~\n";
						break;
					}
				}while(true);
				propnum++;
				continue;
			}else{
				middle("暂无此道具");
				Sleep(700);
				continue;
			}
		}else if(s == "激光笔"){
			if(wj_prop[5] > 0){
				wjdjs--;
				wj_prop[5]--;
				wjyl[propnum] = "激光笔 使用成功~\n";
				middle(wjyl[propnum]);
				if((late_round == 0 || roundnum - late_round - 1 >= CD[idid]) && idid == 3){
					cout << "是否使用 ";
					setTextColor("green");
					cout << "药剂增幅 ";
					setTextColor("");
					cout << "令此道具效果翻倍(是/否~不为'是'判为'否'):";
					string str;
					cin >> str;
					if(str == "是"){
						middle("增幅成功，再多消除一个道具~\n");
						Sleep(500);
						do{
							cout << "你要消除什么(道具)：";
							string s;
							getline(cin, s);
							if(s == "小刀" && em_prop[0] > 0){
								emdjs--;
								em_prop[0]--;
								wjyl[propnum] = "激光笔 使用成功，成功消除恶魔的 小刀 道具~\n";
								break;
							}else if(s == "饮料" && em_prop[1] > 0){
								emdjs--;
								em_prop[1]--;
								wjyl[propnum] = "激光笔 使用成功，成功消除恶魔的 饮料 道具~\n";
								break;
							}else if(s == "放大镜" && em_prop[2] > 0){
								emdjs--;
								em_prop[2]--;
								wjyl[propnum] = "激光笔 使用成功，成功消除恶魔的 放大镜 道具~\n";
								break;
							}else if(s == "手铐" && em_prop[3] > 0){
								emdjs--;
								em_prop[3]--;
								wjyl[propnum] = "激光笔 使用成功，成功消除恶魔的 手铐 道具~\n";
								break;
							}else if(s == "纸杯" && em_prop[4] > 0){
								emdjs--;
								em_prop[4]--;
								wjyl[propnum] = "激光笔 使用成功，成功消除恶魔的 纸杯 道具~\n";
								break;
							}else if(s == "激光笔" && em_prop[5] > 0){
								emdjs--;
								em_prop[5]--;
								wjyl[propnum] = "激光笔 使用成功，成功消除恶魔的 激光笔 道具~\n";
								break;
							}else if(s == "过期药品" && em_prop[6] > 0){
								emdjs--;
								em_prop[6]--;
								wjyl[propnum] = "激光笔 使用成功，成功消除恶魔的 过期药品 道具~\n";
								break;
							}
						}while(true);
					}
				}
				do{
					cout << "你要消除什么(道具)：";
					string s;
					getline(cin, s);
					if(s == "小刀" && em_prop[0] > 0){
						emdjs--;
						em_prop[0]--;
						wjyl[propnum] = "激光笔 使用成功，成功消除恶魔的 小刀 道具~\n";
						break;
					}else if(s == "饮料" && em_prop[1] > 0){
						emdjs--;
						em_prop[1]--;
						wjyl[propnum] = "激光笔 使用成功，成功消除恶魔的 饮料 道具~\n";
						break;
					}else if(s == "放大镜" && em_prop[2] > 0){
						emdjs--;
						em_prop[2]--;
						wjyl[propnum] = "激光笔 使用成功，成功消除恶魔的 放大镜 道具~\n";
						break;
					}else if(s == "手铐" && em_prop[3] > 0){
						emdjs--;
						em_prop[3]--;
						wjyl[propnum] = "激光笔 使用成功，成功消除恶魔的 手铐 道具~\n";
						break;
					}else if(s == "纸杯" && em_prop[4] > 0){
						emdjs--;
						em_prop[4]--;
						wjyl[propnum] = "激光笔 使用成功，成功消除恶魔的 纸杯 道具~\n";
						break;
					}else if(s == "激光笔" && em_prop[5] > 0){
						emdjs--;
						em_prop[5]--;
						wjyl[propnum] = "激光笔 使用成功，成功消除恶魔的 激光笔 道具~\n";
						break;
					}else if(s == "过期药品" && em_prop[6] > 0){
						emdjs--;
						em_prop[6]--;
						wjyl[propnum] = "激光笔 使用成功，成功消除恶魔的 过期药品 道具~\n";
						break;
					}
				}while(true);
				propnum++;
				continue;
			}else{
				middle("暂无此道具");
				Sleep(700);
				continue;
			}
		}else if(s == "过期药品"){
			if(wj_prop[6] > 0){
				wjdjs--;
				wj_prop[6]--;
				if(random(1, 100) <= 40){
					wjh++;
					wjyl[propnum] = "过期药品 使用成功，回了一点血~\n";
					if(wjh >= wj_max){
						wjyl[propnum] = "过期药品 使用成功，血量已达上限~\n";
						wjh = wj_max; 
					}
					middle(wjyl[propnum]);
					if((late_round == 0 || roundnum - late_round - 1 >= CD[idid]) && idid == 3){
						cout << "是否使用 ";
						setTextColor("green");
						cout << "药剂增幅 ";
						setTextColor("");
						cout << "令此道具效果翻倍(是/否~不为'是'判为'否'):";
						string str;
						cin >> str;
						if(str == "是"){
							middle("增幅成功，再回一点血~\n");
							Sleep(500);
							wjh++;
							wjyl[propnum] = "过期药品 使用成功，回复两点血~\n";
							if(wjh >= wj_max){
								wjyl[propnum] = "过期药品 使用成功，血量已达上限~\n";
								wjh = wj_max; 
							}
							late_round = roundnum;
						}
					}
				}else{
					wjh--;
					wjyl[propnum] = "过期药品 使用成功，被扣一点血~\n";
					middle(wjyl[propnum]);
					if((late_round == 0 || roundnum - late_round - 1 >= CD[idid]) && idid == 3){
						cout << "是否使用 ";
						setTextColor("green");
						cout << "药剂增幅 ";
						setTextColor("");
						cout << "令此道具效果翻倍(是/否~不为'是'判为'否'):";
						string str;
						cin >> str;
						if(str == "是"){
							middle("增幅成功，再扣一点血~\n");
							Sleep(500);
							wjh--;
							wjyl[propnum] = "过期药品 使用成功，被扣两点血~\n";
							wjh = max(wjh, 0);
							late_round = roundnum;
						}
					}
				}
				propnum++;
				continue;
			}else{
				middle("暂无此道具");
				Sleep(700);
				continue;
			}
		}else if(s == "0"){
			break;
		}else{
			middle("输入错误");
			Sleep(700);
		} 
	}
	system("cls");
	xsh();
	setTextColor("lightred");
	middle("恶魔行动\n");
	setTextColor("");
	for(int i = 0; i <= cd; i++){
		middle(emyl[i] + "\n");
	}
	cout << "\n";
	setTextColor("blue");
	middle("玩家行动\n");
	setTextColor("");
	for(int i = 0; i < propnum; i++){
		middle(wjyl[i]);
	}
	Sleep(1000);
	getchar();
	for(int i = 1; i <= lk; i++){
		cout << "你要向 恶魔/自己 开枪(切勿乱输，乱输默认开自己)：";
		string s;
		getline(cin, s);
		if(s == "恶魔"){
			if(eorr[nowf] == 0){
				nowf--;
				if(nowf < 0){
					zd();
				}
				middle("你朝 恶魔 开枪，是空弹\n");
				fb = 1;
			}else{
				nowf--;
				if(nowf < 0){
					zd();
				}
				middle("你朝 恶魔 开枪，是实弹，ta扣" + conv_string(fb) + "点血\n");
				emh -= fb;
				fb = 1;
			}
		}else{
			if(eorr[nowf] == 0){
				nowf--;
				if(nowf < 0){
					zd();
				}
				middle("你朝 自己 开枪，是空弹\n");
				lk++;
				fb = 1;
				if(idid == 0){
					if(i == 1 && !fdjsy){
						setTextColor("yellow");
						middle("赌徒 被动技能发动成功，下一枪伤害翻倍~\n");
						fb *= 2;
						setTextColor("");
					}else{
						if(i != 1){
							setTextColor("yellow");
							middle("赌徒 被动技能发动成功，下一枪伤害翻倍~\n");
							fb *= 2;
							setTextColor("");
						}
					}
				}
			}else{
				nowf--;
				if(nowf < 0){
					zd();
				}
				middle("你朝 自己 开枪，是实弹，自己扣" + conv_string(fb) + "点血\n");
				wjh -= fb;
				fb = 1;
			}
		} 
	} 
}

void log(string s){
	fstream f("logs.txt",ios::in|ios::out);
	f<<s;
	f.close();
}

void Buckshot_Roulette(int id){
	system("cls");
	Buckshot_Roulette_Start();
	system("cls");
	system("mode con cols=50 lines=40");
	wjh = lnitial_blood_volume[id];
	wj_max = Maximum_blood_volume[id];
	emh = 8;
	em_max = 8;
	idid = id;
	system("cls");
	zd();
	while(true){
		emdjs++;
		wjdjs++;
		emdjs++;
		wjdjs++;
		em_prop[random(0, 6)]++;
		random(-1, -1);
		em_prop[random(0, 6)]++;
		random(-1, -1);
		wj_prop[random(0, 6)]++;
		random(-1, -1);
		wj_prop[random(0, 6)]++;
		random(-1, -1);
		if(roundnum == 0){
			em_prop[random(0, 6)]++;
			random(-1, -1);
			wj_prop[random(0, 6)]++;
			random(-1, -1);
			emdjs++;
			wjdjs++;
			roundnum++;
			cls();
			continue;
		}
		if(idid == 1){
			int propx =  random(0, 6);
			wj_prop[propx]++;
			random(-1, -1);
			xsh();
			setTextColor("yellow");
			middle("财主 技能生效，多获得 " + name_prop[propx] + " 道具~");
			setTextColor("");
			Sleep(1500);
			system("cls");
			xsh();
		}else{
			xsh();
			Sleep(1500);
		}
		if(nowf < 0){
			zd();
		}
		//恶魔 
		int cd = em_round();
		
		if(wjh <= 0 || emh <= 0){
			break;
		}
		//玩家 
		wj_round(cd);
		
		roundnum++;
		Sleep(1500);
		system("cls");
		
		if(wjh <= 0 || emh <= 0){
			break;
		}
	} 
	system("cls");
	setTextColor("red");
	if(wjh <= 0){
		middle("恶魔胜利\n");
		log("lose\n"); 
	}else{
		middle("玩家胜利\n");
		log("win\n");
	}setTextColor("");
}

void main_emlp();

void Buckshot_Roulette_main(){
	system("cls");
	system("mode con cols=25 lines=17");
	int identity_id = Choose_identity();
	system("mode con cols=25 lines=13");
	int mode_id = choose_mode();
	if(mode_id == 0){
		Buckshot_Roulette(identity_id);
	}
	if(MessageBox (NULL, "要再玩一次吗？", "提示", MB_OKCANCEL|MB_ICONQUESTION) == IDOK){
		main_emlp();
	}
}

void main_emlp(){
	system("cls");
	srand((unsigned)time(0));
	cls();
	system("title 恶魔轮盘");
	system("mode con cols=25 lines=10");
	setTextColor("red");
	cout << "\n\n";
	cout << "       恶 ";
	Sleep(300);
	cout << "魔 ";
	Sleep(300);
	cout << "轮 ";
	Sleep(300);
	cout << "盘\n\n\n";
	Sleep(500);
	cout << "      > 开始 游戏 <\n";
	Sleep(100);
	setTextColor("littlewhite");
	cout << "    按下 回车键 开始"; 
	setTextColor("");
	while(!KEY_DOWN(VK_RETURN)){
		cls();
	}
	if(MessageBox (NULL, "确定要开始吗？", "提示", MB_OKCANCEL|MB_ICONQUESTION) == IDOK){
		Buckshot_Roulette_main();
	}
}

int main(){
	main_emlp();
	return 0;
}



